<?php
/**
 * AuthController class file.
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */

abstract class ExtAuthController extends ExtBasicFormController
{
    protected abstract function authenticateUser($username,$password);
    protected abstract function getRedirectUrl();

    /**
     * If this method returns null then defaukt ExtJS theme will be used
     * @return string e.g. 'gray'
     */
    protected function getExtJSTheme()
    {
        return null;
    }

    protected function getLoginView()
    {
        return 'ext4yii.app.views.ExtAuthBasicView';
    }

    public function actionLogin()
    {
        $this->layout='ext4yii.app.layouts.basic';
        $this->render($this->getLoginView());
    }

    public function Save($data)
    {
        $result = array();
        $auth = $this->authenticateUser($_POST['username'], $_POST['password']) == true ? true : false;
        if($auth)
            $result['url'] = $this->getRedirectUrl();
        $result['success'] = $auth;
        
        return $result;
    }

    public function Load()
    {
    }
}
?>
